using ASP;
using HoWave.Web;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.UI;
using System.Web.UI.WebControls;
public class Shop_UserControls_HowaveSearch : UserControl
{
	protected DropDownList SearchType;
	protected TextBox SearchText;
	protected DropDownList SearchClass;
	protected Button SearchButton;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		this.SearchText.Attributes.Add("onfocus", "this.className='searchIn'");
		this.SearchText.Attributes.Add("onblur", "this.className='searchOut'");
		this.SearchButton.Attributes.Add("onmouseover", "this.className='SearchBtnOver'");
		this.SearchButton.Attributes.Add("onmouseout", "this.className='SearchBtnOut'");
		this.InitSearchBox();
	}
	protected void SearchButton_Click(object sender, EventArgs e)
	{
		string text = this.SearchType.SelectedValue.Trim();
		string text2 = this.SearchText.Text.Trim();
		string text3 = this.SearchClass.SelectedValue.Trim();
		string text4 = this.Page.Request.Url.ToString().ToLower();
		int num = text4.IndexOf("/shop/");
		string text5 = text4;
		if (num > 1)
		{
			text5 = text5.Substring(0, num);
		}
		else
		{
			num = text5.ToLower().IndexOf("index.aspx");
			if (num > 0)
			{
				text5 = text5.Substring(0, num - 1);
			}
		}
		string url;
		if (text == "Product")
		{
			url = string.Concat(new string[]
			{
				text5,
				"/Shop/Search/Search_Product.aspx?page=1&title=",
				text2,
				"&type=",
				text,
				"&parentid=",
				text3
			});
		}
		else
		{
			string text6 = "";
			string text7 = "";
			if (text == "ShopOwner")
			{
				text6 = text2;
			}
			else
			{
				text7 = text2;
			}
			url = string.Concat(new string[]
			{
				text5,
				"/Shop/Search/Search_Shop.aspx?page=1&shopname=",
				text7,
				"&shopsaler=",
				text6,
				"&classid=",
				text3
			});
		}
		if (text2 != "")
		{
			Shop_HotKey shop_HotKey = new Shop_HotKey();
			shop_HotKey.AddHotKey(text2, url);
		}
		base.Response.Redirect(url);
	}
	protected void InitSearchBox()
	{
		if (base.Request["type"] != null)
		{
			this.SearchType.SelectedValue = base.Request["type"];
		}
		if (base.Request["title"] != null && base.Request["title"] != "")
		{
			this.SearchText.Text = base.Request["title"];
		}
		Shop_Class shop_Class = new Shop_Class();
		DataTable rootClass = shop_Class.GetRootClass();
		this.SearchClass.DataSource = rootClass;
		this.SearchClass.DataTextField = "ClassName";
		this.SearchClass.DataValueField = "ClassID";
		this.SearchClass.DataBind();
		rootClass.Dispose();
		if (base.Request["ParentID"] != null && base.Request["ParentID"] != "")
		{
			bool flag = false;
			foreach (ListItem listItem in this.SearchClass.Items)
			{
				if (listItem.Value == base.Request["ParentID"])
				{
					listItem.Selected = true;
					flag = true;
					break;
				}
			}
			if (!flag)
			{
				DataTable classMapPathByParentID = shop_Class.GetClassMapPathByParentID(Convert.ToInt32(base.Request["ParentID"]));
				if (classMapPathByParentID.Rows.Count > 0)
				{
					for (int i = 0; i < classMapPathByParentID.Rows.Count; i++)
					{
						ListItem item = new ListItem(classMapPathByParentID.Rows[i]["ClassName"].ToString(), classMapPathByParentID.Rows[i]["ClassID"].ToString());
						this.SearchClass.Items.Add(item);
					}
					this.SearchClass.SelectedValue = base.Request["ParentID"];
				}
				classMapPathByParentID.Dispose();
			}
		}
	}
}
